package com.example.demo.identity.domain;

import com.example.demo.identity.domain.QIdentityUser;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.util.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;

import java.util.UUID;

@Repository
public interface IdentityUserRepository extends JpaRepository<IdentityUser, UUID>, QuerydslPredicateExecutor<IdentityUser> {

    default Page<IdentityUser> pageList(String userName, Pageable pageable) {
        var query = Expressions.asBoolean(true).isTrue();
        if (!StringUtils.isNullOrEmpty(userName)) {
            query = query.and(QIdentityUser.identityUser.userName.eq(userName));
        }
        return findAll(query, pageable);
    }
}
